package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20240915060148CreateUsersTable struct {
}

// Signature The unique signature for the migration.
func (r *M20240915060148CreateUsersTable) Signature() string {
	return "20240915060148_create_users_table"
}

// Up Run the migrations.
func (r *M20240915060148CreateUsersTable) Up() error {
	if !facades.Schema().HasTable("users") {
		return facades.Schema().Create("users", func(table schema.Blueprint) {
			table.ID("id")
			//table.Integer("tenant_id").Nullable().Default(0).Unsigned().Comment("租户id")
			table.String("username").Nullable().Comment("用户名")
			table.String("email").Nullable().Comment("邮箱")
			table.String("password").Nullable().Comment("密码")
			table.TinyInteger("status").Default(1).Comment("1:开启 2:关闭")
			table.TinyInteger("is_root").Default(0).Comment("是否系统用户,有全部权限不显示在界面")
			table.Timestamps()
			table.SoftDeletes()

			table.Unique("username", "is_root", "deleted_at")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20240915060148CreateUsersTable) Down() error {
	return facades.Schema().DropIfExists("users")
}
